﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Arch.Intercep;

namespace Arch.Aspects
{
    [AttributeUsage(AttributeTargets.Property)]
    public class AutoNow : Attribute, IMemberAspectInterceptor
    {
        public void Intercept(object entity, MemberInfo member)
        {
            ((PropertyInfo) member).GetSetMethod().Invoke(entity, new object[] { DateTime.Now });
        }

        public AutoNow()
        {
            Targets = ActionTarget.Creating |ActionTarget.Updating| ActionTarget.Deleting ;
        }

        public virtual ActionTarget Targets { get; protected set; }
    }
}
